<?php 
$url = $this->baseUrl();
?>
<div class="container-fluid">

<div class="row-fluid" style="background-color: white;">

	<div class="social-box">
		<div class="header" style="border-bottom: 0;">
		<h4 class="">
		<i class="icon-pushpin main-color"></i> Sản phẩm
		</h4>
		</div>	

		<div class="body" style="padding: 0;">

		<div class="span4" style="padding: 10px;">
			
				<address>		
					<img src="<?php echo $url;?>/photo/<?php echo $this->product["image"]?>" width="200px" height="200px" />
				</address>
				<address>
					<?php echo $this->product["detail"];?>
				</address>
				<address>
				<strong><?php echo $this->shop["name"]?></strong><br>
				<?php echo $this->shop["address1"]?><br>				
				<i class="icon-phone-sign"></i> + <?php echo $this->shop["phone1"];?>
				</address>	
				<address>
					<iframe style="border: 0;" width="100%" src="http://www.facebook.com/plugins/like_box.php?href=https://www.facebook.com/<?php echo $this->shop["pageid"];?>&show_faces=true&header=false&stream=false&show_border=false&width=800"></iframe>
				</address>			
		
		</div>
		
		
		<div class="span8" style="padding: 10px; position: relative;">
			
			<div id="canvas_loading_shop" style="display: none; text-align: center; margin-top: 25px;" >
				<img alt="Circle_loader_cover" id="canvas_loading_spinner_shop" src="http://d1x1klo9zku3iu.cloudfront.net/assets/circle_loader_cover-f0de6de2b230746f2f712cb563b81879.gif">
				<div id="image-uploading-progress-text-shop">Hệ thống đang lưu thông tin. Vui lòng đợi...</div>
			</div>
	
			<div id="canvas_loading_success_shop" style="display: none;margin-top: 25px;" >		
				<div id="image-uploading-progress-text-success-shop">Bạn đã đặt mua thành công! Thông tin của bạn sẽ được Chủ Shop xử lý và liên lạc lại bạn trong thời gian ngắn nhất. Cảm ơn bạn.</div>
			</div>
			
			<form id="myForm" class="row-fluid" method="post" action="<?php echo $url;?>/shop/index/updateorder">
				<input type="hidden" name="productid" value="<?php echo $this->product["id"]; ;?>">
				<input type="hidden" name="shopid" value="<?php echo $this->shop["id"]; ;?>">
				<div class="span5" style="margin-left: 0; margin-right: 10px;">
					<label>Tên</label><input class="span12" placeholder="Tên" type="text" id="displayname" name="displayname" value=""><br>
					<label>Số điện thoại</label><input class="span12" placeholder="Số điện thoại" type="text" id="phone" name="phone" value=""><br>
					<label>Quận/Huyện</label><input class="span12" placeholder="Quận/Huyện" type="text" id="district" name="district" value="" /><br>	
				</div>
				<div class="span5">
					<label>E-Mail</label><input class="span12" placeholder="E-Mail" type="text" id="email" name="email" value=""><br>
					<label>Địa chỉ</label><input class="span12" placeholder="Địa chỉ" type="text" id="address" name="address" value=""></textarea><br>
					<label>Tỉnh/Thành phố</label><input class="span12" placeholder="Tỉnh/Thành phố" type="text" id="province" name="province" value="" /><br>	
				</div>				
				
				<div style="clear: left;">
					<label>Số lượng</label>
					<select class="span5" name="number-product" style="width: 80px;">
						<option>1</option>
						<option>2</option>
						<option>3</option>
						<option>4</option>
						<option>5</option>
						<option>6</option>
						<option>7</option>
						<option>8</option>
						<option>9</option>
						<option>10</option>
					</select>					
					<label>Hình thức thanh toán</label>					
						<select class="span5" name="payment_method">					
							<option value="direct">Thanh toán trực tiếp</option>
							<option value="bank">Thanh toán chuyển khoản qua ngân hàng</option>
							<option value="cod">Thanh toán COD (Nhận hàng và Thanh toán)</option>					
						</select>				
					<br>				
					<label>Ghi chú(nếu có)</label><textarea placeholder="Ghi chú" class="span12" name="note" style="height: 35px;"></textarea><br>
					<label>&nbsp;</label><input class="btn btn-large btn-primary" type="button" id="btn-contact"  value="Đặt mua">
				</div>
			</form>
			
		</div>
				
	</div>	
	</div>
	
	
	
</div>

</div>
<div id="fb-root"></div>

<script>

(function(){

	var options = {
	        //target:        '#tutor',   // target element(s) to be updated with server response
	        beforeSubmit:  showRequest,  // pre-submit callback
	        success:       showResponse  // post-submit callback
	       
	};
	
	$('#btn-contact').click(function() {

		if(checkForm()){

			$("#canvas_loading_shop").show();
			$("#image-uploading-progress-text-shop").show();
			$('#myForm').hide();		
			$('#myForm').submit();    

		}		
	});
	
	// bind form using 'ajaxForm'
	 // bind to the form's submit event 
	$('#myForm').submit(function() { 
	    // inside event callbacks 'this' is the DOM element so we first 
	    // wrap it in a jQuery object and then invoke ajaxSubmit
	    $(this).ajaxSubmit(options); 
	
	    // !!! Important !!! 
	    // always return false to prevent standard browser submit and page navigation 
	    return false; 
	}); 
	
	
	// pre-submit callback
	function showRequest(formData, jqForm, options) {
	
	    var queryString = $.param(formData);
	
	    return true;
	}
	
	// post-submit callback
	function showResponse(responseText, statusText, xhr, $form)  {
		$("#canvas_loading_shop").hide();
		$("#image-uploading-progress-text-shop").hide();
		$("#canvas_loading_success_shop").show();
		$("#image-uploading-progress-text-success-shop").show();
	}
})();

</script>

<script type="text/javascript">// <![CDATA[

function checkForm(){

	var reg1 = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	// check email	
    var email = $("#email").val();

    var flag = true; 

    var s ="";
    
    if(reg1.test(email) == false) {

    	s += "email";
    	flag = false; 

    }

    //check displayname
    var displayname = $("#displayname").val();
	if(displayname == ""){
		s += ", tên";
    	flag = false;
	}
	
    //check phone
    var phone = $("#phone").val();
    if(phone == ""){
		s += ", số điện thoại";
    	flag = false;
	}
	
    //check address
    var address = $("#address").val();
    if(address == ""){
		s += ", địa chỉ";
    	flag = false;
	}
	
    //check district
    var district = $("#district").val();
    if(district == ""){
		s += ", quận/huyện";
    	flag = false;
	}

    //check province
    var province = $("#province").val();
    if(province == ""){
		s += ", tỉnh/thành phố";
    	flag = false;
	}

    if(flag == false){
		alert("Vui lòng điền đầy đủ thông tin ("+s+")");
		return false;
    }

    return true;
	
}

(function(){

	var signinWin;
	$('#btn-buy').click(function () {
	        
		signinWin = window.open("https://www.facebook.com/dialog/permissions.request?_path=permissions.request&app_id=475289012560274&redirect_uri=http://apps.facebook.com/thietdep/product=<?php echo $this->product["id"];?>&buy=yes&response_type=token&perms=email&fbconnect=1&from_login=1&m_sess=1&rcount=1","_parent", "");
	        setTimeout(CheckLoginStatus, 2000);
	        signinWin.focus();
	        return false;
	        
	    });

	function CheckLoginStatus() {
	    if (signinWin.closed) {
	       // $('#UserInfo').text($.cookie("some_cookie");
	    }
	    else setTimeout(CheckLoginStatus, 1000);
	}
	
})();



    window.fbAsyncInit = function() {
        FB.init({
            appId: '475289012560274',
            cookie: true,
            xfbml: true,
            oauth: true
        });
        FB.Event.subscribe('auth.login', function(response) {
            window.location.reload();
        });
        FB.Event.subscribe('auth.logout', function(response) {
            window.location.reload();
        });
        FB.Canvas.setAutoGrow();
        };
        (function() {
            var e = document.createElement('script'); e.async = true;
            e.src = document.location.protocol +
            '//connect.facebook.net/en_US/all.js';
            document.getElementById('fb-root').appendChild(e);
        }());

        
        
// ]]></script>
